package user

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/user/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
	tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	in := &v1.ListInput{}
	in.TenantCode = tenantCode
	in.Page = req.Page
	in.Size = req.Size
	in.EmployeeNo = req.EmployeeNo
	in.Fullname = req.Fullname
	in.Phone = req.Phone
	in.Username = req.Username
	out, err := service.User().List(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.ListRes{Total: out.Total, Data: make([]v1.User, 0)}
	for _, v := range out.Data {
		t := v1.User{
			Username:   v.Username,
			Email:      v.Email,
			Id:         v.Id,
			Fullname:   v.Fullname,
			Phone:      v.Phone,
			Status:     v.Status,
			Type:       v.Type,
			EmployeeNo: v.EmployeeNo,
		}
		res.Data = append(res.Data, t)
	}
	return res, nil

}
